package com.xing.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Mybatis-Plus 数据自动填充类
 */
@Primary
@Component(value = "myMetaObjectHandlerByAdmin")
public class MyMetaObjectHandler implements MetaObjectHandler {
    private static final String CREATE_TIME = "createDate";
    private static final String UPDATE_TIME = "updateDate";

    @Override
    public void insertFill(MetaObject metaObject) {
        strictInsertFill(metaObject, CREATE_TIME, Date::new, Date.class);
        strictInsertFill(metaObject, UPDATE_TIME, Date::new, Date.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        strictInsertFill(metaObject, UPDATE_TIME, Date::new, Date.class);
    }
}
